package com.ovo.rxandroiddemo.app;

import android.Manifest;
import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ovo.rxandroiddemo.utils.PermissionsUtils;

import butterknife.ButterKnife;

public abstract class BaseActivity extends Activity implements PermissionsUtils.IPermissionsResult {

    private String[] permisions = new String[]{
            Manifest.permission.INTERNET/*,
            Manifest.permission.CALL_PHONE,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE*/
    };

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionsUtils.getInstance().onRequestPermissionsResult(this, requestCode, permissions, grantResults);
    }

    @Override
    public void passPermissons() {
        initView();
    }

    @Override
    public void forbitPermissons() {

    }

    public abstract int initLayout();

    public abstract void initView();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(initLayout());
        ButterKnife.bind(this);
        BaseApplication.activity = this;
        BaseApplication.context = this;

        PermissionsUtils.getInstance().
                chekPermissions(this, permisions, this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        BaseApplication.activity = this;
        BaseApplication.context = this;
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
